package com.chuangjiangx.member.manager.common;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * 浏览器响应头
 *
 * @author 李孝延
 * @Date 2017/12/30 11:31
 **/
public class RequestHeadersUtil {

    /**
     * 导出文件名称
     *
     * @param response       response
     * @param exportFileName 导出文件的名称
     * @throws UnsupportedEncodingException 异常
     */
    public static void exportRequestHeader(HttpServletResponse response, String exportFileName) throws UnsupportedEncodingException {
        String fileName = exportFileName + System.currentTimeMillis();
        //fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
        fileName = new String(fileName.getBytes("GB2312"), "ISO_8859_1");
        response.setHeader("Content-Type", "application/force-download");
        response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", fileName + ".csv"));
        response.setContentType("application/csv;charset=utf-8");
    }
}
